﻿using System.IO;

namespace HCore
{
    public static class FileUtility
    {
        public static bool Save(OutputMemeryBitStream output, string destPath)
        {
            using (BinaryWriter writer = new BinaryWriter(File.Open(destPath, FileMode.Create)))
            {
                writer.Write(output.GetBuffer(), 0, output.GetByteLength());
            }

            return true;
        }

        public static InputMemoryBitStream Open(string srcPath)
        {
            if (!File.Exists(srcPath))
            {
                Logger.LogWarning(srcPath + "not Exists");
                return null;
            }

            using (BinaryReader reader = new BinaryReader(File.Open(srcPath, FileMode.Open)))
            {
                return new InputMemoryBitStream(reader.ReadBytes((int)reader.BaseStream.Length), (int)reader.BaseStream.Length);
            }
        }
    }
}